var e = require("../../services/baseURL.js"),
  t = require("../../utils/util.js"),
  o = (require("../../utils/qs.js"),
    getApp());

Page({
  data: {
    disabled: !1,
    showPhone: !1,
    userinfo: {},
  },
  onLoad: function(e) {
    var that = this;
    //查看是否授权
    that.onSetting();
  },
  
  //查看是否授权
  onSetting: function(e){
    var that = this;
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: res => {
              that.setData({
                userinfo: res.userInfo,
                showPhone: !0
              });
            }
          });
        } else {
          disabled: !0
        }
      }
    });
  },
  //获取用户信息
  userInfo:function(res){
    
  },
  //点击授权
  userInfoHandle: function(e){
    if (e.detail.userInfo){
      //用户按了允许授权的按钮
      var that = this
      that.onSetting();
    }else{
      //用户按了拒绝按钮
      wx.showModal({
        title: '警告',
        content: '您点击了拒绝授权，将无法进入小程序，请授权之后再进入!!!',
        showCancel: false,
        confirmText: '返回授权',
        success: function(res){
          if (res.confirm){
            
          }
        }
      });
    }
  },

  //获取手机号
  getPhoneNumber: function(e){
    var that = this
    wx.login({
      success: res=> {
        if (res.code){
          that.goHome();
          return false;
          console.log(e.detail.encryptedData);
          wx.request({
            url: '',
            data: {
              encryptedData: e.detail.encryptedData,
              iv: e.detail.iv,
              signature: e.detail.signature,
              code: res.code
            },
            success: function(r){
                if(r.code == 200){
                  wx.showToast({
                    title: "绑定成功",
                  });
                }
            },
            fail: function(){
              wx.showModal({
                title: "提示",
                content: "绑定失败",
              });
            }
          });
        } else{
          wx.showModal({
            title: "提示",
            content: "授权失败"
          });
        }
      }
    });
  },

  //暂不授权 离开当前页面
  goHome: function () {
    wx.switchTab({
      url: "/pages/index/index"
    });
  },
});